package top.wyloop.fasthome.module.system.model.entity;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Index;
import jakarta.persistence.Table;
import jakarta.persistence.Transient;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.GenericGenerator;
import top.wyloop.fasthome.util.PrimaryKeyGenerator;

import java.util.Date;

/**
 * @author Wyatt6
 * @date 2025/5/9
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Entity
@Table(name = "tb_system_user", indexes = {
        @Index(columnList = "username", unique = true),
        @Index(columnList = "nickname", unique = true),
})
public class User {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY, generator = "PK_generator")
    @GenericGenerator(name = "PK_generator", type = PrimaryKeyGenerator.class)
    private Long id;            // 主键
    @Column(nullable = false)
    private String username;    // 用户名
    @Column(nullable = false)
    private String password;    // 密码
    @Column(nullable = false)
    private String salt;        // 加密盐
    @Column
    private String nickname;    // 昵称
    @Column
    private String avatarName;  // 头像文件名
    @Column
    private Long homeId;        // 所属家庭ID
    @Column
    private Date registerTime;  // 注册时间
    @Column
    private Date lastLoginTime; // 最近登录时间

    // ----- 非持久化属性 -----
    @Transient
    private String captchaKey;  // 验证码KEY
    @Transient
    private String captcha;     // 验证码
    @Transient
    private String newPassword; // 新密码
}
